function Create_New_BusObject(NewBO)
%{
Creates Simulink bus object.
Inputs:
  NewBO         :A structure containing the following two fields of
                    information for the bus object.
  NewBO.Name    :String containint name of bus object being created.
  Elements      :Cell containing the elements of the bus object in the
                  following format.

Elements = {ElementName   Dimensions  DataType}

Example:
    BO_new.Name = 'BO_test';
    BO_new.Elements = {'Element1'   1   'double';
                       'Element2'   1   'double';
                       'Vector1'    3   'double';
                       'Inputflg'   1   'boolean'};
    
    Create_New_BusObject(BO_new);

Modification info:
Date Modified       Modified By         Modification Made
8-17-2014           Peter Hernandez     Created Function
%}
BOName = NewBO.Name;
Elements = NewBO.Elements;
[m,~] = size(Elements);

clear elems
for p=1:1:m
    elems(p) = Simulink.BusElement;
    elems(p).Name = Elements{p,1};
    elems(p).Dimensions = Elements{p,2};
    elems(p).DimensionsMode = 'Fixed';
    elems(p).DataType = Elements{p,3};
    elems(p).SampleTime = -1;
    elems(p).Complexity = 'real';
    elems(p).SamplingMode = 'Sample based';
    elems(p).Min = [];
    elems(p).Max = [];
end

BOprops = Simulink.Bus;
BOprops.HeaderFile = '';
BOprops.Description = sprintf('');
BOprops.DataScope = 'Auto';
BOprops.Alignment = -1;
BOprops.Elements = elems;
assigninContext(BOName,BOprops)